package dome1;


import java.util.Arrays;

public class Text {
    public static void main(String[] args) {
        System.out.println(args.length);
        for(String x : args) {
            System.out.println(x);
        }
    }
    public static void main7(String[] args) {
        int[] arr = {2,5,9,4,6,7,3,1};
        bobbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void bobbleSort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if(arr[j] > arr[j+1]) {
                    int tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j+1] = tmp;
                }
            }
        }
    }
    public static void main6(String[] args) {
        int[] arr = {1,2,5,6,7,8,9};
        System.out.println(binarySeach(arr, 5));
    }
    public static int binarySeach(int[] arr,int find) {
        int left = 0;
        int right = arr.length-1;
        while(left<=right) {
            int mid = left + ((right - left) >> 1);
            if(arr[mid]>find) {
                right = mid - 1;
            }else if(arr[mid]<find) {
                left = mid + 1;
            }else {
                return mid;
            }
        }
        return -1;
    }

//    public static int[] copyOf(int[] arr) {
//        int[] ret = new int[arr.length];
//        for (int i = 0; i < arr.length; i++) {
//            ret[i] = arr[i];
//        }
//        return ret;
//    }
    public static void main5(String[] args) {
        int[] arr = {1,2,3,4,5};
        //newArr1与arr是同一个数组
        int[] newArr1 = arr;
        System.out.println(Arrays.toString(newArr1));
        System.out.println("*************");
        //全部拷贝
        int[] newArr2 = Arrays.copyOf(arr,arr.length);
        System.out.println(Arrays.toString(newArr2));
        System.out.println("*************");
        //局部拷贝,[2,4)
        int[] newArr3 = Arrays.copyOfRange(arr,2,4);
        System.out.println(Arrays.toString(newArr3));
    }
    public static void main4(String[] args) {
        int[] arr = {1,2,3,4,5};
        String newArr = Arrays.toString(arr);
        System.out.println(newArr);
    }
    public static void main3(String[] args) {
        int[] arr = fib(10);
        for(int x : arr) {
            System.out.println(x);
        }
    }
    public static int[] fib(int n) {
        if(n<=0) {
            return null;
        }else {
            int[] arr = new int[n];
            arr[0] = arr[1] = 1;
            for (int i = 2; i < n; i++) {
                arr[i] = arr[i-1] + arr[i-2];
            }
            return arr;
        }
    }
    public static void main2(String[] args) {
        int[] arr = {1,2,3};
        System.out.println(arr[0]);//1
        func1(arr);
        System.out.println(arr[0]);//10
    }

    public static void func1(int[] arr) {
        arr[0] = 10;
    }
    public static void main1(String[] args) {
        int[] arr = {1,2,3};
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i] + " ");
        }
    }
}
